Hello,
I've been writing a small .net C# app to log/plot some
data. To test it
I'm running this C program on a thread in Kflop, it just
printf's some
hardcoded data in a loop:
#include "ExtendedLogging.h"
main()
{
Delay_sec(1.5);
int i = 0;
double T0 = Time_sec();
printf("Running Simple Thread...\n");
for(i=0;i<10;i++)
{
double tcurr = Time_sec() - T0;
// round times to neaarest servo tick
double tickcurr = ((int)(tcurr/TIMEBASE + 0.5))*TIMEBASE;
printf("%f,%d,%d,%d\n",tickcurr,40,60,80);
Delay_sec(1.5);
}
printf("Exiting Simple Thread.\n");
}
What I've found is that the Console Handler on the PC side
only gets
called if I periodically grab a lock on the KM_Controller
object, which
I'm doing in a thread like so:
async Task MsgTask()
{
LogTo.Info("Enter LoggingService.MsgTask");
//grab a Token to the KM_Controller so that the Console
Handler is called
while (!_cancelSource.IsCancellationRequested)
{
try
{
if (_kMotionService.KMController.WaitToken(100) ==
KMOTION_TOKEN.KMOTION_LOCKED)
{
//just grab it and release it, this seems to be
all that is needed to trigger
//the controller to call the Console Handler
_kMotionService.KMController.ReleaseToken();
}
await Task.Delay(100);
}
catch (OperationCanceledException)
{
break;
}
}
LogTo.Info("Exit LoggingService.MsgTask");
}
This is similar to what the SimpleFormsCS sample does but
it uses a timer.
So my question is: is that how it is supposed to work?
Seems odd that I
need to grab a lock to the KM_Controller to get the
messages sent to the
console handler.
I'm using 4.34a, VS2015.
Thanks.
Greg.